class RecipesController < ApplicationController
  before_filter :authenticate
  
  def index
    @recipes = Recipe.all
  end
  
  def new
    @recipe = Recipe.new    
  end
  
  def create
    @recipe = Recipe.new(params[:recipe])
    if @recipe.save
      flash[:notice] = "Category was successfully created."
      redirect_to_admin
    else
      render :action => :new      
    end
  end
  
  def show
    @recipes = Recipe.find(:all, :conditions => {:group => params[:id]})
  end
  
  def edit
    @recipe = Recipe.find(params[:id])
  end
  
  def update
    @recipe = Recipe.find(params[:id])    
    if @recipe.update_attributes(params[:recipe])
      flash[:notice] = 'Recipe was successfully updated.'
      redirect_to_admin
    else
      render :action => :edit
    end
  end
  
  def manage
    @recipe = Recipe.find params[:id]
    @categories = Category.all
  end
  
  def update_sortable
    @recipe = Recipe.find params[:id]
    @recipe.sortable(params[:items])
    render :file => "articles/update_sortable.js"
  end
end
